package com.zkthink.ceres.order.dao;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.zkthink.base.mapper.SuperMapper;
import com.zkthink.ceres.order.dto.AdminOrderDTO;
import com.zkthink.ceres.order.dto.AdminOrderSearchParamDTO;
import com.zkthink.ceres.order.dto.ReturnDTO;
import com.zkthink.ceres.order.entity.MoneyReturn;
import com.zkthink.ceres.order.entity.Order;

import java.util.Map;

import com.zkthink.ceres.product.dto.PageQueryDTO;
import com.zkthink.database.mybatis.conditions.query.LbqWrapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * 
 * </p>
 *
 * @author JustArgo
 * @date 2020-05-10
 */
@Repository
public interface OrderMapper extends SuperMapper<Order> {

    /** 根据状态和分页查询指定用户的订单
     * @author JustArgo 2020/5/13 0:20
     * @return
     */
    List<Order> findOrderListByStatusAndPage(@Param("mid")Long mid, @Param("orderStatus")Integer orderStatus,
                                             @Param("start")int start, @Param("pageSize")int pageSize);

    /** 管理后台搜索订单符合的数量
     * @author JustArgo 2020/5/21 21:08
     * @return
     */
    Integer searchAdminOrderListCount(AdminOrderSearchParamDTO adminOrderSearchParamDTO);

    /** 管理后台搜索订单
     * @author JustArgo 2020/5/21 21:05
     * @return
     */
    List<AdminOrderDTO> searchAdminOrderList(AdminOrderSearchParamDTO adminOrderSearchParamDTO);

    /** 管理后台搜索售后单符合的数量
     * @author JustArgo 2020/5/21 21:08
     * @return
     */
    Integer searchAdminReturnOrderListCount(@Param("orderStatus")Integer orderStatus, @Param("keywordType")Integer keywordType, @Param("keyword")String keyword, @Param("returnStatus")Integer returnStatus, @Param("returnType")Integer returnType, @Param("dealType")Integer dealType);

    /** 管理后台搜索售后单
     * @author JustArgo 2020/5/21 21:05
     * @return
     */
    List<AdminOrderDTO> searchAdminReturnOrderList(@Param("orderStatus")Integer orderStatus, @Param("keywordType")Integer keywordType, @Param("keyword")String keyword, @Param("returnStatus")Integer returnStatus, @Param("returnType")Integer returnType, @Param("dealType")Integer dealType);

    /** 关闭待付款超过15分钟的订单
     * @author JustArgo 2020/5/26 22:57
     * @return
     * @param overDate
     */
    int closeOvertimeOrder(Date overDate);

    /** 自动确认收货
     * @author JustArgo 2020/5/27 20:18
     * @return
     */
    int autoReceiveGoods(Date overDate);

    /** 查询订单数量
     * @author JustArgo 2020/5/30 13:58
     * @return
     */
    Integer findOrderListByStatusAndPageCount(@Param("mid")Long mid, @Param("orderStatus")Integer orderStatus);

    /**
     * 统计当天店铺订单数据
     * @return
     */
    Map<String,Object> countTodayOrder(String tenantCode);

    /** 查询售后单列表
     * @author JustArgo 2020/5/30 23:04
     * @return
     */
    List<ReturnDTO> selectReturnList(PageQueryDTO pageQueryDTO);

    /** 删除订单
     * @author JustArgo 2020/5/31 13:31
     * @return
     */
    int delOrderById(@Param("mid")Long mid, @Param("id")Long orderId);

    /** 根据订单
     * @author JustArgo 2020/5/31 19:58
     * @return
     */
    @SqlParser(filter = true)
    Order selectByIdIgnoreTenant(Long orderId);

    /** 查询售后单数量
     * @author JustArgo 2020/7/16 16:09
     * @return
     */
	Integer selectReturnOrderCount(Long mid);

	/**
	 * @author JustArgo 2020/7/16 16:31
	 * @return
	 */
	Long selectOrderSumByMid(Long mid);

	/**
	 * @author JustArgo 2020/7/16 16:38
	 * @return
	 */
    Integer selectBuyProductCount(Long mid);
}
